package com.topisv.tms.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.topisv.tms.entity.EdiOrderItem;

public interface EdiOrderItemDao extends PagingAndSortingRepository<EdiOrderItem, Long>{
	
	
	List<EdiOrderItem> findByCustomerCodeAndOrdeno(String customerCode,String ordeno);
	List<EdiOrderItem> findByCrtimeBetween(Date fromDate,Date endDate);
	
	List<EdiOrderItem> findByOrdeno(String ordeno);
	
	@Query("select t from EdiOrderItem t where t.ordeno in ?1")
	List<EdiOrderItem> findByOrderno(List<String> ordenos);
	
	
	List<EdiOrderItem> findByWaybillNo(String waybillNo);
	
	@Modifying
	@Query("delete  from  EdiOrderItem e where e.customerCode=?1 and e.ordeno=?2")
	void deleteOrdeno(String customerCode,String ordeno);
	
	@Query(nativeQuery=true, value="select sku_id, sum(qty) qty from edi_order_item a where  a.ordeno=:orderno group by a.sku_id")
	List<Object[]> queryOrdernosQty(@Param("orderno") String orderno);

}
